//
//  bianjiCXView.m
//  Gxj
//
//  Created by 💋索少杰 on 2017/9/8.
//  Copyright © 2017年 wkq. All rights reserved.
//

#import "bianjiCXView.h"
#import "MeetingView.h"

@interface bianjiCXView ()<UITextViewDelegate>

#define Start_X          190.0f      // 第一个按钮的X坐标
#define Start_Y          70.0f     // 第一个按钮的Y坐标
#define Width_Space      15.0f      // 2个按钮之间的横间距
#define Height_Space     20.0f     // 竖间距
#define Button_Height   15.0f    // 高
#define Button_Width    30.0f    // 宽

@end
@implementation bianjiCXView

- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        
        self.backgroundColor=[UIColor whiteColor];
        
        [self addSubview:self.headingsText];
        [self addSubview:self.xiahuxianView];
        [self addSubview:self.zhutiText];
        [self addSubview:self.biaoqianBut];
        [self addSubview:self.downchoiceFB];
        [self addSubview:self.xiahuxianViewOne];
        [self addSubview:self.keywordsText];
        [self addSubview:self.viewbj];
        [self addSubview:self.butImage];
        [self addSubview:self.butVideo];
        [self addSubview:self.butLink];
        [self addSubview:self.butWord];
        

        [self showEditStromView];
        
    }
    return self;
}

- (void)showEditStromView
{
    _headingsText.sd_layout
    .topSpaceToView(self, kHeightScale(10))
    .leftSpaceToView(self, kWidthScale(5))
    .rightSpaceToView(self, kWidthScale(10))
    .heightIs(kHeightScale(40));
    
    _xiahuxianView.sd_layout
    .topSpaceToView(_headingsText, kHeightScale(2))
    .leftSpaceToView(self, kWidthScale(10))
    .rightSpaceToView(self, kWidthScale(10))
    .heightIs(kHeightScale(1));
    
    _zhutiText.sd_layout
    .topSpaceToView(self.xiahuxianView, kHeightScale(14))
    .leftEqualToView(self.xiahuxianView)
    .widthIs(kWidthScale(160))
    .autoHeightRatio(0);
    
    _downchoiceFB.sd_layout
    .topSpaceToView(self.xiahuxianView, kHeightScale(17))
    .rightSpaceToView(self, kWidthScale(10))
    .widthIs(kWidthScale(10))
    .heightIs(kHeightScale(10));
    
    _xiahuxianViewOne.sd_layout
    .topSpaceToView(self.zhutiText, kHeightScale(15))
    .leftSpaceToView(self, kWidthScale(10))
    .rightSpaceToView(self, kWidthScale(10))
    .heightIs(kHeightScale(1));
    
    _keywordsText.sd_layout
    .topSpaceToView(self.xiahuxianViewOne, kHeightScale(10))
    .leftSpaceToView(self, kWidthScale(10))
    .rightSpaceToView(self, kWidthScale(10))
    .heightIs(kHeightScale(150));
    
    _viewbj.sd_layout
    .bottomSpaceToView(self, kHeightScale(0))
    .leftSpaceToView(self, kWidthScale(0))
    .rightSpaceToView(self, kWidthScale(0))
    .heightIs(kHeightScale(114));
    
    _butImage.sd_layout
    .bottomSpaceToView(self, kHeightScale(83))
    .leftSpaceToView(self, kWidthScale(23))
    .widthIs(kWidthScale(40/2))
    .heightIs(kHeightScale(40/2));
    
    _butVideo.sd_layout
    .bottomSpaceToView(self, kHeightScale(83))
    .leftSpaceToView(self.butImage, kWidthScale(162/2))
    .widthIs(kWidthScale(40/2))
    .heightIs(kHeightScale(40/2));
    
    _butLink.sd_layout
    .bottomSpaceToView(self, kHeightScale(83))
    .leftSpaceToView(self.butVideo, kWidthScale(162/2))
    .widthIs(kWidthScale(40/2))
    .heightIs(kHeightScale(40/2));
    
    _butWord.sd_layout
    .bottomSpaceToView(self, kHeightScale(83))
    .leftSpaceToView(self.butLink, kWidthScale(162/2))
    .widthIs(kWidthScale(40/2))
    .heightIs(kHeightScale(40/2));
    
    

}

- (UITextView *)headingsText
{
    if (!_headingsText)
    {
        _headingsText = [[UITextView alloc] init];
        _headingsText.text=@"请输入创想标题：";
        [_headingsText setValue:[UIColor whiteColor] forKeyPath:@"_placeholderLabel.textColor"];
        //_biaotiText.backgroundColor = [UIColor colorWithWhite:0 alpha:0.0];
        _headingsText.textColor=[UIColor lightGrayColor];
        _headingsText.delegate=self;
        _headingsText.font=[UIFont systemFontOfSize:kWidthScale(16)];
    }
    return _headingsText;
}
- (UIImageView *)xiahuxianView
{
    if (!_xiahuxianView)
    {
        _xiahuxianView= [[UIImageView alloc] init];
        _xiahuxianView.image = [UIImage imageNamed:@"hui"];
    }
    return _xiahuxianView;
}
- (UILabel *)zhutiText
{
    if (!_zhutiText)
    {
        _zhutiText=[[UILabel alloc] init];
        _zhutiText.text=@"请选择响应标签(必填)";
        _zhutiText.textColor=[UIColor blackColor];
        _zhutiText.font=[UIFont systemFontOfSize:kWidthScale(15)];
    }
    return _zhutiText;
}
- (UIButton *)downchoiceFB
{
    if (!_downchoiceFB)
    {
        _downchoiceFB=[[UIButton alloc] init];
        _downchoiceFB.backgroundColor=[UIColor lightGrayColor];
        [_downchoiceFB setBackgroundImage:[UIImage imageNamed:@"xiala"] forState:UIControlStateNormal];
    }
    return _downchoiceFB;
}
- (UIImageView *)xiahuxianViewOne
{
    if (!_xiahuxianViewOne)
    {
        _xiahuxianViewOne= [[UIImageView alloc] init];
        _xiahuxianViewOne.image = [UIImage imageNamed:@"hui"];
    }
    return _xiahuxianViewOne;
}

- (UITextView *)keywordsText
{
    if (!_keywordsText)
    {
        _keywordsText = [[UITextView alloc] init];
        _keywordsText.text=@"编辑创想：";
        [_keywordsText setValue:[UIColor whiteColor] forKeyPath:@"_placeholderLabel.textColor"];
        //_biaotiText.backgroundColor = [UIColor colorWithWhite:0 alpha:0.0];
        _keywordsText.textColor=[UIColor lightGrayColor];
        _keywordsText.delegate=self;
        _keywordsText.font=[UIFont systemFontOfSize:kWidthScale(15)];
    }
    return _keywordsText;
}
- (UIView *)viewbj
{
    if (!_viewbj)
    {
        _viewbj=[[UIView alloc] init];
        _viewbj.backgroundColor=[UIColor lightGrayColor];
    }
    return _viewbj;
}
- (UIButton *)butImage
{
    if (!_butImage)
    {
        _butImage=[[UIButton alloc] init];
        [_butImage setTitle:@"照片" forState:UIControlStateNormal];
        [_butImage setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        _butImage.titleLabel.font = [UIFont systemFontOfSize:kWidthScale(9)];
        _butImage.titleEdgeInsets = UIEdgeInsetsMake(40, _butImage.titleLabel.bounds.size.width, 0, 0);//设置title在button上的位置（上top，左left，下bottom，右right）
        //  [button setContentEdgeInsets:UIEdgeInsetsMake(70, 0, 0, 0)];//
        [_butImage setBackgroundImage:[UIImage imageNamed:@"tupian"] forState:UIControlStateNormal];
    }
    return _butImage;
}
- (UIButton *)butVideo
{
    if (!_butVideo)
    {
        _butVideo=[[UIButton alloc] init];
        [_butVideo setTitle:@"视频" forState:UIControlStateNormal];
        [_butVideo setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        _butVideo.titleLabel.font = [UIFont systemFontOfSize:kWidthScale(9)];
        _butVideo.titleEdgeInsets = UIEdgeInsetsMake(40, _butVideo.titleLabel.bounds.size.width, 0, 0);//设置title在button上的位置（上top，左left，下bottom，右right）
        //  [button setContentEdgeInsets:UIEdgeInsetsMake(70, 0, 0, 0)];//
        [_butVideo setBackgroundImage:[UIImage imageNamed:@"shipin"] forState:UIControlStateNormal];
    }
    return _butVideo;
}
- (UIButton *)butLink
{
    if (!_butLink)
    {
        _butLink=[[UIButton alloc] init];
        [_butLink setTitle:@"链接" forState:UIControlStateNormal];
        [_butLink setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        _butLink.titleLabel.font = [UIFont systemFontOfSize:kWidthScale(9)];
        _butLink.titleEdgeInsets = UIEdgeInsetsMake(40, _butLink.titleLabel.bounds.size.width, 0, 0);//设置title在button上的位置（上top，左left，下bottom，右right）
        //[_butLink setContentEdgeInsets:UIEdgeInsetsMake(70, 0, 0, 0)];//
        [_butLink setBackgroundImage:[UIImage imageNamed:@"lianjie"] forState:UIControlStateNormal];
    }
    return _butLink;
}
- (UIButton *)butWord
{
    if (!_butWord)
    {
        _butWord=[[UIButton alloc] init];
        [_butWord setTitle:@"文字" forState:UIControlStateNormal];
        [_butWord setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        _butWord.titleLabel.font = [UIFont systemFontOfSize:kWidthScale(9)];
        _butWord.titleEdgeInsets = UIEdgeInsetsMake(40, _butWord.titleLabel.bounds.size.width, 0, 0);//设置title在button上的位置（上top，左left，下bottom，右right）
        //  [button setContentEdgeInsets:UIEdgeInsetsMake(70, 0, 0, 0)];//
        [_butWord setBackgroundImage:[UIImage imageNamed:@"wenzi"] forState:UIControlStateNormal];
    }
    return _butWord;
}
- (UIButton *)biaoqianBut
{
    if (!_biaoqianBut)
    {
        //商业标签
        NSArray*arr=@[@"shangye",@"fuzhuang",@"UI",@"UI",@"UI",@"UI"];
        for (int i = 0 ; i < 3; i++) {
            NSInteger index = i % 3;
            NSInteger page = i / 3;
            
            // 圆角按钮
            _biaoqianBut = [UIButton buttonWithType:UIButtonTypeRoundedRect];
            _biaoqianBut.tag = i;//这句话不写等于废了
            _biaoqianBut.frame = CGRectMake(index * (Button_Width + Width_Space) + Start_X, page  * (Button_Height + Width_Space )+Start_Y, Button_Width, Button_Height);
            [_biaoqianBut setBackgroundImage:[UIImage imageNamed:arr[index]] forState:UIControlStateNormal];
            [self addSubview:_biaoqianBut];
            //按钮点击方法
            //[mapBtn addTarget:self action:@selector(mapBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        }
    }
    return _biaoqianBut;
}

#pragma mark - UITextViewDelegate 文本输入
- (void)textViewDidEndEditing:(UITextView *)textView
{
    if(_keywordsText.text.length < 1){
        textView.text = @"编辑创想：";
        textView.textColor = [UIColor lightGrayColor];
    }else if (_headingsText){
        textView.text = @"请输入创想标题：";
        textView.textColor = [UIColor lightGrayColor];
    }
}
- (void)textViewDidBeginEditing:(UITextView *)textView
{
    if([_keywordsText.text isEqualToString:@""]){
        textView.text=@"";
        textView.textColor=[UIColor lightGrayColor];
    }else if (_headingsText){
        textView.text=@"";
        textView.textColor=[UIColor lightGrayColor];
    }
}


@end
